import {
  BarSeriesOption,
  LineSeriesOption,
  ScatterSeriesOption,
} from "echarts";
import { BaseRenderTypes } from "./types";

export type BaseRendersOptions =
  | LineSeriesOption
  | BarSeriesOption
  | ScatterSeriesOption;

const BaseRanders = (opt: BaseRendersOptions) => {
  if (BaseRenderTypes.includes(opt.type || "")) {
    throw new Error("渲染类型验证失败 ");
  }

  return {
    type: opt.type,
    label: {
      show: true,
      position: opt?.label?.position || "top",
      padding: [0, 0, -5, 0],
      color: opt.color,
      fontSize: 8,
    },
    smooth: true,

    color: opt.color,
    xAxisIndex: opt.xAxisIndex,
    yAxisIndex: opt.yAxisIndex,
    data: opt.data,
  };
};

export default BaseRanders;
